﻿using glb;
using Newtonsoft.Json;
using PIMS.DBModel;
using PIMS.Interface;
using PIMS.Utils;
using PIMS.WorkPlugin.EAS;
using PIMS.WorkPlugin.ORM;
using PIMS.WorkPlugin.Util;
using PIMS.WorkPlugin.Util.Config;
using PIMS.XmlModel;
using PIMS.YongXiang;
using PIMS_Interface.Interface;
using SqlSugar;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using ZXing;
using 金蝶星瀚系统;
using 金蝶星瀚系统.KingDeeResponse;
using static Org.BouncyCastle.Math.EC.ECCurve;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TreeView;

namespace PIMS.WorkPlugin
{
    public partial class FormManual : Form
    {
        PIMSConfigX pimsConfig = null;
        PrintDocument PrinterBox;
        private IDebugMsg debug = null;
        private ILog4net log = null;
        int lineCount = 0;
        Dictionary<string, string> typeDict = new Dictionary<string, string>();
        Dictionary<string, string> templateDict = new Dictionary<string, string>();
        Dictionary<string, string> codeDict = new Dictionary<string, string>();
        string regkeypath = RegistryTool.baseRegPath + "FormManual";
        int num_pack = 0, lineIndex = 0;
        Bitmap qrBmp;
        string boxBarcode,batch;
        string lableConfigFile = AppDomain.CurrentDomain.BaseDirectory + "箱标签配置.xml";
        LabelXmlPrintHelper xmlPrint = null;

        public orderformcurrent RetValue { get; set; }

        private DataTable dtLocal = null;

        public DataTable GetResult
        {
            get
            {
                return this.dtLocal;
            }
        }

        public FormManual()
        {
            InitializeComponent();

            pimsConfig = XmlHelper.XmlFileToObject<PIMSConfigX>(AppDomain.CurrentDomain.BaseDirectory + "config\\PIMSConfig.xml");
            PrinterBox = new PrintDocument();
            PrinterBox.PrintController = new StandardPrintController(); //取消打印弹窗
            //FontTitle = new Font("微软雅黑", 14, FontStyle.Bold);
            //FontText = new Font("微软雅黑", 10);
            //FontTail = new Font("微软雅黑", 6);

            //绑定打印事件
            PrinterBox.PrintPage += Printer_PrintPageBox;
            xmlPrint = new LabelXmlPrintHelper(lableConfigFile);
        }

        /// <summary>
        /// 注：反射加载时会自动调用一次
        /// </summary>
        public void Init(IDebugMsg debugMsg, ILog4net log4net)
        {
            this.debug = debugMsg;
            this.log = log4net;
        }

        private void FormPrint_Load(object sender, EventArgs e)
        {
            List<string> list = GetLocalPrinter();
            this.cmbPrint.Items.Clear();
            foreach (string str in list)
            {
                this.cmbPrint.Items.Add(str);
            }
            this.cmbPrint.Text = RegistryTool.ReadReg(regkeypath, "箱标打印机");
            try
            {
                this.Text = "人工线打印箱标<默认使用围板箱，如需使用纸箱，需将‘使用纸箱’打勾>";
                int.TryParse(pimsConfig.GetAppValueByKey("lineCount"), out lineCount);
                InitComboBoxByString(this.cb包装线, pimsConfig.GetAppValueByKey("deviceName"));
                InitComboBoxByDataDic(this.定制料信息, "硅料类型");
                InitComboBoxByDataDic(this.客户单位, "客户单位");

                string cmd = string.Concat(new string[]
                {
                  "select * from 产品型号定义表 where 使能='1' ",
                  "order by ID"
                });

                DataTable product = SqlSugarHelper.QueryToDataTable<ProductType>(cmd);
                for (int i = 0; i < product.Rows.Count; i++)
                {
                    if ((product.Rows[i]["模板ID"].ToString() != "" && product.Rows[i]["模板ID"].ToString() != "0"))
                    {
                        this.型号.Items.Add(product.Rows[i]["型号"].ToString());
                        typeDict.Add(product.Rows[i]["型号"].ToString(), product.Rows[i]["粒径"].ToString());
                        templateDict.Add(product.Rows[i]["型号"].ToString(), product.Rows[i]["模板ID"].ToString());
                        codeDict.Add(product.Rows[i]["型号"].ToString(), product.Rows[i]["物料编码"].ToString());
                    }
                }

                UpdateBatchNo();
				string plant = pimsConfig.GetAppValueByKey("plant");

                cb使用型号代号.Checked= true;

               
				if (plant == "A" || plant == "B" || plant == "C")
                {
                    this.cb使用单层袋.Checked = true;
                }

            }
            catch (Exception ex)
            {
                this.log.Error("", ex);
                MessageBox.Show(ex.Message, "NG", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.err.Clear();
            if (String.IsNullOrEmpty(this.cmbPrint.Text))
            {
                this.err.SetError(this.cmbPrint, "禁止为空！");
                return;
            }
            if (String.IsNullOrEmpty(this.型号.Text))
            {
                this.err.SetError(this.型号, "禁止为空！");
                return;
            }
            if (rb_EAS.Checked && String.IsNullOrEmpty(this.EAS生产批次.Text))
            {
                this.err.SetError(this.EAS生产批次, "禁止为空！");
                return;
            }
            if (rb_手输.Checked && String.IsNullOrEmpty(this.手输批号.Text))
            {
                this.err.SetError(this.手输批号, "禁止为空！");
                return;
            }
            if (!ByteCode.IsNumeric(this.辅材重.Text))
            {
                this.err.SetError(this.辅材重, "要求纯数字!");
                return;
            }
            if (String.IsNullOrEmpty(this.包装批次.Text))
            {
                this.err.SetError(this.包装批次, "禁止为空！");
                return;
            }
            if (0 >= num_pack)
            {
                this.err.SetError(this.label10, "请选择包装箱数！");
                return;
            }


            DialogResult dr = MessageBox.Show("确认打印箱标吗？生产箱数：" + num_pack.ToString(), "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (dr == DialogResult.Yes)
            {
                btnOK.Enabled = false;
                this.batch = true == rb_手输.Checked ? 手输批号.Text : EAS生产批次.Text;
                for (int count = 0; count < num_pack; count++)
                {
                    string barcode = DJGHelper.GeneralSerialNum(this.lineIndex);
                    this.qrBmp = QRCODE.ZxingQRCode.GenerateQRCode(barcode);
                    this.boxBarcode = barcode;
                    //注销登陆不影响，取上一次成功登陆的用户中文名
                    string regkeypath = @"SOFTWARE\PIMS\FormMain";
                    string operMan = RegistryTool.ReadReg(regkeypath, "LoginUserName");
                    try
                    {
                        //this.ProduceBox(barcode);
                        #region 使用事务，保存袋信息及箱信息
                        using (SqlSugarClient db = SqlSugarHelper.GetDb())
                        {
                            try
                            {
                                db.BeginTran();//开启事务

                                #region 保存箱信息
                                saveddata save = new saveddata();
                                save.line = 0;
                                save.packager = cb包装线.Text;
                                save.workOrder = DateTime.Now.ToString("yyyyMMDDHHmmss");
                                save.uid = barcode; //箱号
                                save.batchNo = this.batch; //批号
                                save.productName = 型号.Text;        //品名
                                save.productMark = 粒径.Text;        //规格
                                save.count = "60";                      //袋数
                                save.weight = "600";                    //满箱净重

                                save.reserved1 = 辅材重.Value.ToString();  //毛重
                                save.reserved2 = 定制料信息.Text;       //定制料信息
                                save.reserved3 = 客户单位.Text;         //客户单位
                                save.reserved4 = operMan;               //装箱人员
                                save.reserved5 = 包装批次.Text;         //包装批次
                                save.reserved6 = "";                    //车号
                                //save.reserved8 = "";                    //是否报废
                                //save.reserved11 = Mcode;              //物料编码
                                save.reserved13 = "0";                  //强排标志
                                save.reserved15 = "0";                  //缠膜标识
                                save.productTime = DateTime.Now;
                                db.Insertable<saveddata>(save).ExecuteCommand();
                                #endregion

                                db.CommitTran(); //提交事务
                            }
                            catch (Exception ex)
                            {
                                this.log.Error("", ex);
                                this.debug.DebugMsg("事务发生错误，回滚操作 " + ex.Message);
                                db.RollbackTran(); //回滚
                                return;
                            }

                        }
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "软件发生异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    //上传EAS系统                                              
                    string msg = KingDee.Import_CartonInfo(barcode);

                    if (!msg.Contains("Err"))
                    {
                        this.debug.DebugMsg("上传EAS成功！箱号:" + barcode);
                        this.log.Info("上传EAS成功！箱号:" + barcode);
                        this.debug.DebugMsg("---------------------------------------------------------------------------------");
                        btnOK.Enabled = true;
                    }
                    else
                    {
                        this.debug.DebugMsg("上传EAS失败！"+msg);
                        this.debug.DebugMsg("---------------------------------------------------------------------------------");
                        this.log.Info("上传EAS失败！" + msg);
                        btnOK.Enabled = true;
                        MessageBox.Show("上传EAS失败！");
                        return;
                    }
                   
                    //qrBmp = 标签打印程序.ZxingQRCode.GenerateQRCode(barcode);
                    xmlPrint.barcode = barcode;
                    for (int i = 0; i < 1; i++)
                    {
                        //指定打印机，非默认
                        PrinterBox.PrinterSettings.PrinterName = this.cmbPrint.Text; //"Microsoft XPS Document Writer";
                                                                                  //加入注释
                        PrinterBox.PrinterSettings.PrintToFile = true;
                        PrinterBox.Print();
                    }
                }
            }
            
            //this.Close();         
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.dtLocal = null;
            this.Close();
        }


        private void InitComboBoxByString(ComboBox comboBox,string value)
        {
            comboBox.Items.Clear();
            string[] strs = value.Split('|');
            for(int i=0;i<strs.Length;i++)
            {
                comboBox.Items.Add(strs[i]);
            }
            if(comboBox.Items.Count==1)
            {
                comboBox.SelectedIndex = 0;
            }
        }

        private void InitComboBoxByDataDic(ComboBox comboBox,string type,string separ="|")
        {
            string where = string.Format("type='{0}'",type);
            List<datadictionary> list = SqlSugarHelper.QueryList<datadictionary>(where, 0, "");
            comboBox.Items.Clear();
            foreach (datadictionary data in list)
            {
                comboBox.Items.Add(data.value);
            }
        }


        private void button1_Click_1(object sender, EventArgs e)
        {
            this.button1.Enabled = false;
            this.EAS生产批次.Enabled = false;
            KingDee.GetManufacturebatch();
            this.button1.Enabled = true;
            this.EAS生产批次.Enabled = true;

            UpdateBatchNo();
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            this.btnRefresh.Enabled = false;
            this.包装批次.Items.Clear();

            string batch = "";
            if (rb_EAS.Checked && String.IsNullOrEmpty(EAS生产批次.Text))
            {
                MessageBox.Show("请选择EAS生产批次！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.btnRefresh.Enabled = true;
                return;
            }
            if (rb_手输.Checked && String.IsNullOrEmpty(手输批号.Text))
            {
                MessageBox.Show("请输入生产批次！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.btnRefresh.Enabled = true;
                return;
            }
            if (rb_EAS.Checked)
            {
                batch = EAS生产批次.Text;
            }
            else if (rb_手输.Checked)
            {
                batch = 手输批号.Text;
            }

            try
            {
                this.包装批次.Items.Clear();

                List < PackageBatch > list = KingDee.GetPackageBatch(batch);

                //List<PackageBatch> list = JsonConvert.DeserializeObject<List<PackageBatch>>(json);
                if (list != null && list.Count > 0)
                {                      
                    foreach (PackageBatch pb in list)
                    {
                        if(!this.cb使用单层袋.Checked)
                        {
                            if (pb.pacBantchNo.Contains("单层袋"))
                                continue;
                        }
                        else
                        {
                            if (pb.pacBantchNo.Contains("双层袋"))
                                continue;
                        }
                        if (!this.cb使用纸箱.Checked)
                        {
                            if (pb.pacBantchNo.Contains("围板箱"))
                            {
                                this.包装批次.Items.Add(pb.pacBantchNo);
                            }
                        }
                        else
                        {
                            if (pb.pacBantchNo.Contains("纸箱"))
                            {
                                this.包装批次.Items.Add(pb.pacBantchNo);
                            }
                        }
                    }
                    MessageBox.Show("查询成功！", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                this.debug.DebugMsg("查询生产批号接口发生错误", InfoLevel.error);
                this.log.Error(ex.Message,ex);
                MessageBox.Show(ex.Message, "查询生产批号接口发生错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            this.btnRefresh.Enabled = true;
        }

        private bool TypeCheck(string type, string packageBatch)
        {
            if (String.IsNullOrEmpty(type) || String.IsNullOrEmpty(packageBatch))
            {
                return false;
            }
            string[] strs = 包装批次.Text.Split('/');

            if(packageBatch.Contains("N型") && !type.Contains("N型"))
            {
                return false;
            }
            if (!packageBatch.Contains("N型") && type.Contains("N型"))
            {
                return false;
            }

            string str = type.Substring(type.Length - 2);
            if (str.ToUpper().StartsWith("S"))
            {
                if (strs[1] == str && strs[2].Contains(type.Substring(0, type.Length - 2)))
                {
                    return true;
                }
            }
            return false;
        }

        private void cb使用纸箱_CheckedChanged(object sender, EventArgs e)
        {
            this.包装批次.Items.Clear();
        }

        private void UpdateBatchNo()
        {           
            string cmd = string.Concat(new string[]
           {
              "select top ",
              ConfigManager.AppSettings["easTop"].Value,
              " * from EASBatch ",
              "order by CreateAt desc"
           });
            // DataTable recordEas = DbHelperSQL.Queryy(cmd);
            DataTable recordEas = SqlSugarHelper.QueryToDataTable<EASBatch>(cmd);
            if (recordEas != null && recordEas.Rows.Count > 0)
            {
                this.EAS生产批次.Items.Clear();
                for (int i = 0; i < recordEas.Rows.Count; i++)
                {
                    this.EAS生产批次.Items.Add(recordEas.Rows[i]["Batch"].ToString());
                }
            }
        }

        private void EAS生产批次_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.EAS生产批次.Text == "")
            {
                this.btnRefresh.Enabled = false;
            }
            else
            {
                this.btnRefresh.Enabled = true;
            }
            this.包装批次.Items.Clear();
        }

        private void 手输批号_TextChanged(object sender, EventArgs e)
        {
            if (this.手输批号.Text.Length > 6)
            {
                this.btnRefresh.Enabled = true;
            }
            else
            {
                this.btnRefresh.Enabled = false;
            }
            this.包装批次.Items.Clear();
        }

        /// <summary>
        /// json 对特殊字符的处理
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static String StringToJson(String s)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < s.Length; i++)
            {
                char c = s[i];
                switch (c)
                {
                    case '\"':
                        sb.Append("\\\"");
                        break;
                    case '\\':
                        sb.Append("\\\\");
                        break;
                    case '/':
                        sb.Append("\\/");
                        break;
                    case '\b':
                        sb.Append("\\b");
                        break;
                    case '\f':
                        sb.Append("\\f");
                        break;
                    case '\n':
                        sb.Append("\\n");
                        break;
                    case '\r':
                        sb.Append("\\r");
                        break;
                    case '\t':
                        sb.Append("\\t");
                        break;
                    default:
                        sb.Append(c);
                        break;
                }
            }
            return sb.ToString();
        }

        private void rb_手输_CheckedChanged(object sender, EventArgs e)
        {
            if (rb_手输.Checked)
            {
                this.手输批号.Enabled = true;
                this.EAS生产批次.Enabled = false;
            }
        }

        private void rb_EAS_CheckedChanged(object sender, EventArgs e)
        {
            if (rb_EAS.Checked)
            {
                this.EAS生产批次.Enabled = true;              
                this.手输批号.Enabled = false;
                this.手输批号.Text = "YX-";
            }
        }

        private void 包装批次_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(包装批次.Text))
            {
                string batch = "";
                if (rb_EAS.Checked)
                {
                    batch = EAS生产批次.Text;
                }
                else if (rb_手输.Checked)
                {
                    batch = 手输批号.Text;
                }

                if (包装批次.Text.Contains("纸箱"))
                {
                    辅材重.Value = 620;
                }
                else
                {
                    辅材重.Value = 640;
                }              


                if (String.IsNullOrEmpty(batch))
                {
                    MessageBox.Show("生产批次为空!", "出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                string[] strs = 包装批次.Text.Split('/');
                if (strs[0] == batch)
                {
                    if (cb使用型号代号.Checked)
                    {
                        this.型号.Text = strs[2].Replace("料", "");
                    }
                    else
                    {
                        this.型号.Text = strs[2].Replace("料", "") + strs[1];
                    }                       
                }
                else
                {
                    this.型号.Text = String.Empty;
                    MessageBox.Show("包装批次有误!与生产批次不符。", "出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                this.型号.Text = String.Empty;
                this.粒径.Text = "";
                //this.模板ID.Text = "";
            }
        }

        private void 型号_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(型号.Text))
            {
                粒径.Text = typeDict[型号.Text];
                //模板ID.Text = templateDict[型号.Text];
                //labelCode.Text = codeDict[型号.Text];
            }
            else
            {
                粒径.Text = "";
                //模板ID.Text = "";
                //labelCode.Text = "";
            }
        }

        private void cb使用单层袋_CheckedChanged(object sender, EventArgs e)
        {
            this.包装批次.Items.Clear();
        }

        private void cb使用型号代号_CheckedChanged(object sender, EventArgs e)
        {
            if(cb使用型号代号.Checked)
            {
                RegistryTool.WriteReg(regkeypath, "cb使用型号代号", "1");
            }
            else
            {
                RegistryTool.WriteReg(regkeypath, "cb使用型号代号", "0");
            }
        }

        private void radioButton_CheckedChanged(object sender, EventArgs e)
        {
            RadioButton rb = (RadioButton)sender;
            if (rb.Checked)
            {
                switch(rb.Name)
                {
                    case "radioButton3":
                        num_pack = Int32.Parse(numericUpDown1.Value.ToString());
                        break;
                    default:
                        num_pack = Int32.Parse(rb.Text);
                        break;
  
                }

            }
        }

        void Printer_PrintPageBox(object sender, PrintPageEventArgs e)
        {
            #region 直写
            ////永祥箱标 尺寸 95*60 有效尺寸 93*58
            //Pen pen = new Pen(Brushes.Black, 1);
            ////int x = 2;
            //e.Graphics.DrawRectangle(pen, 2, 10 - 6, 74 * 5 - 6, 45 * 5 - 6);
            //e.Graphics.DrawLine(pen, 2, 13 * 5, 74 * 5 - 6, 13 * 5);
            //e.Graphics.DrawLine(pen, 2, (13 + 8) * 5, 45 * 5, (13 + 8) * 5);
            //e.Graphics.DrawLine(pen, 2, (13 + 8 * 2) * 5, 45 * 5, (13 + 8 * 2) * 5);
            //e.Graphics.DrawLine(pen, 2, (13 + 8 * 3) * 5, 45 * 5, (13 + 8 * 3) * 5);

            //e.Graphics.DrawLine(pen, 15 * 5, 13 * 5, 15 * 5, 45 * 5 - 1);
            //e.Graphics.DrawLine(pen, 45 * 5, 13 * 5, 45 * 5, 45 * 5 - 1);

            ////Font FontHead = new Font("黑体", 15.5f);  //宋体 楷体 华为中宋 方正小标宋简体 FontStyle.Bold
            ////Font FontHead2 = new Font("Arial", 8.5f, FontStyle.Regular);
            ////62*69Pix
            ////e.Graphics.DrawImage(YongXiangProject.Properties.Resources.xiangbiao1, 80, 25, 270, 39);  
            //e.Graphics.DrawImage(PIMS.WorkPlugin.Properties.Resources.YongxiangLogo, 10, 15, 45, 45);
            ////e.Graphics.DrawImage(YongXiangProject.Properties.Resources.xb, 80, 25, 250, 33);
            ////e.Graphics.DrawImage()
            ////e.Graphics.DrawString("四川永祥新能源有限公司", FontHead, Brushes.Black, 80, 25);
            ////e.Graphics.DrawString("Sichuan Yongxiang Newenergy Co.,Ltd.", FontHead2, Brushes.Black, 99, 45);           


            //Font FontBody = new Font("黑体", 11, FontStyle.Regular);
            //e.Graphics.DrawString("型 号", FontBody, Brushes.Black, 2 * 5 + 6, 15 * 5 + 4);
            //StringFormat stringFormat = new StringFormat();
            //stringFormat.LineAlignment = StringAlignment.Center;
            //stringFormat.Alignment = StringAlignment.Center;
            ////stringFormat.
            //RectangleF lbRect = new RectangleF(70, 65, 150, 40);

            //e.Graphics.DrawString(this.型号.Text, FontBody, Brushes.Black, lbRect, stringFormat);

            ////e.Graphics.DrawString(this.型号.Text, FontBody, Brushes.Black, 23 * 5, 15 * 5+4);
            //e.Graphics.DrawString("批 号", FontBody, Brushes.Black, 2 * 5 + 6, 23 * 5 + 1);
            //e.Graphics.DrawString(this.batch, FontBody, Brushes.Black, 16 * 5 + 10, 23 * 5 + 1);
            //e.Graphics.DrawString("重 量", FontBody, Brushes.Black, 2 * 5 + 6, 31 * 5);
            //string weight = "";
            //if (!String.IsNullOrEmpty(this.辅材重.Text))
            //{
            //    weight = this.辅材重.Text + "KG";
            //}
            //e.Graphics.DrawString(weight, FontBody, Brushes.Black, 23 * 5, 31 * 5);
            //e.Graphics.DrawString("粒 径", FontBody, Brushes.Black, 2 * 5 + 6, 40 * 5);
            //e.Graphics.DrawString(this.粒径.Text, FontBody, Brushes.Black, 23 * 5, 40 * 5);

            //e.Graphics.DrawImage(this.qrBmp, 47 * 5 - 3, 15 * 5, 125, 125);
            //e.Graphics.DrawString(this.boxBarcode, FontBody, Brushes.Black, 47 * 5, 41 * 5);
            #endregion

            #region 读取xml文件
            //横向打印
            e.PageSettings.Landscape = true;

            //string weight = "";
            //if (!String.IsNullOrEmpty(this.辅材重.Text))
            //{
            //    weight = this.辅材重.Text + "KG";
            //}

            Dictionary<string, string> myDict = new Dictionary<string, string>();
            myDict.Add("型号", this.型号.Text);
            myDict.Add("批号", batch);
            myDict.Add("重量", "600KG");
            myDict.Add("粒径", this.粒径.Text);
            myDict.Add("箱标", xmlPrint.barcode);
            xmlPrint.CreateLabelByXml(e.Graphics, myDict);

            #endregion
        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            if (radioButton3.Checked)
            {
                num_pack = int.Parse(numericUpDown1.Value.ToString());
            }
        }

        private void cmbPrint_SelectedIndexChanged(object sender, EventArgs e)
        {
            RegistryTool.WriteReg(regkeypath, "箱标打印机", this.cmbPrint.Text);
        }

        private void cb包装线_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (0 <= cb包装线.SelectedIndex)
            {
                switch(cb包装线.Text)
                {
                    case "人工包装1":
                        lineIndex = 22;
                        break;
                    case "人工包装2":
                        lineIndex = 23;
                        break;
                    case "人工包装3":
                        lineIndex = 24;
                        break;
                    case "人工包装4":
                        lineIndex = 26;
                        break;
                    case "人工包装5":
                        lineIndex = 27;
                        break;
                }
            }
        }

        /// <summary>
        ///  获取本地打印机的列表，第一项就是默认打印机
        /// </summary>
        public static List<string> GetLocalPrinter()
        {
            List<string> fPrinters = new List<string>();
            foreach (string fPrinterName in PrinterSettings.InstalledPrinters)
            {
                if (!fPrinters.Contains(fPrinterName))
                    fPrinters.Add(fPrinterName);
            }
            return fPrinters;
        }
    }
}
